package sk.ygor.xtemplate;

import java.util.List;
import java.util.LinkedList;
import java.util.Map;

public class Content implements Part {

	private List<ContentToken> tokens;

	public Content(String contentData) {
		tokens = new LinkedList<ContentToken>();
		ContentTokenizer tokenizer = new ContentTokenizer(contentData);
		ContentToken token;
		while ((token = tokenizer.nextToken()) != null) {
			tokens.add(token);
		}
	}

	public String toString() {
		return tokens.toString();
	}


	public String getText(Map<String, Object> space) throws XTemplateException {
		StringBuilder sb = new StringBuilder();
		for (ContentToken token: tokens) {
			sb.append(token.getText(space));
		}
		return sb.toString();
	}
}
